package kotan.controller._kotan;

import java.io.ObjectOutputStream;

import kotan.datastore.api.DatastoreApiUtil;

import org.slim3.controller.Controller;
import org.slim3.controller.Navigation;
import org.slim3.datastore.Datastore;

import com.google.appengine.api.datastore.Entity;

/**
 * controller for _kotan/load
 * @author shuji.w6e
 * @since 1.0
 */
public class LoadController extends Controller {

    @Override
    public Navigation run() throws Exception {
        // TODO many entities
        String kind = super.asString("kind");
        ObjectOutputStream output = new ObjectOutputStream(response.getOutputStream());
        for (Entity entity : Datastore.query(kind).asIterable()) {
            output.writeObject(DatastoreApiUtil.convert(entity));
        }
        response.flushBuffer();
        return null;
    }
    
}
